package com.adou.p2p.model;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import com.adou.p2p.domain.entiry.User;
import com.fasterxml.jackson.annotation.JsonProperty;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserValue {
	@JsonProperty("id")
	private Long id;
	
	@NotNull
	@Size(max =255)
	@JsonProperty("username")
	private String username;
	
	@NotNull
	@Size(max =255)
	@JsonProperty("password")
	private String password;
	
	
	public static UserValue fromEntity(User user){
		if(user == null) {
			return null;
		}
		
		return UserValue.builder()
				.id(user.getId())
				.username(user.getUsername())
				.password(user.getPassword())
				.build();
	}
	
	public static User fromEntity(UserValue value){
		return User.builder()
				.id(value.getId())
				.username(value.getUsername())
				.password(value.getPassword())
				.build();
	}
	
}
